const express = require("express");
const messageServ = require("../services/messageService");
const getSendData = require("../utils/getSendData");

const router = express.Router();

router.get("/", async (req, res, next)=>{

    res.send(getSendData(await messageServ.getMessages(+req.query.page, +req.query.limit, req.query.blogId !== undefined ? +req.query.blogId : -1, req.headers.authorization)));
});

router.post("/", async (req, res, next) => {
    res.send(getSendData(await messageServ.addMessage(req.body)));
});

router.delete("/:id", async (req, res, next) => {
    res.send(getSendData(await messageServ.deleteMessage(req.params.id)));
});

module.exports = router;
